<template>
	<view class="agreement">
		<web-view :src="url" @action="bindmessage"></web-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				url:"",
				isAd:false
			}
		},
		onLoad(e) {
			if(e.type == 1){
				this.url = "https://youchaojingpin.com/app/platformAgreement.html"
				uni.setNavigationBarTitle({
					title:"平台服务协议"
				})
			}else if(e.type == 2){
				this.url = "https://youchaojingpin.com/app/privacyPolicy.html"
				uni.setNavigationBarTitle({
					title:"隐私权政策"
				})
			}else if(e.type == 3){
				this.url = "https://youchaojingpin.com/app/softwareProtocol.html"
				uni.setNavigationBarTitle({
					title:"软件许可使用协议"
				})
			}else if(e.type == 4){
				this.url = "https://youchaojingpin.com/app/paymentAgreement.html"
				uni.setNavigationBarTitle({
					title:"支付服务协议"
				})
			}else{
				this.url = e.url
				uni.setNavigationBarTitle({
					title:e.title,
				})
				this.isAd = true;
			}	
		},
		methods:{
			bindmessage(e){
				console.log(e)
				if(this.isAd == false){
					return
				}
				console.log(1)
				uni.downloadFile({
						url: 'https://youchaojingpin.oss-cn-beijing.aliyuncs.com/youchaoImgs/youchaoruchaoquan.png',
						success: (res) =>{
							if (res.statusCode === 200){
								uni.saveImageToPhotosAlbum({
									filePath: res.tempFilePath,
									success: function() {
										uni.showToast({
											title: "保存成功",
											icon: "none"
										});
									},
									fail: function() {
										uni.showToast({
											title: "保存失败，请稍后重试",
											icon: "none"
										});
									}
								});
							}
						}
					})
			}
		}
	}
</script>

<style>
</style>
